<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>ini配置 | 课程介绍</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../chapter10/10.2_xml配置.html" />
    
    
    <link rel="prev" href="../chapter10/index.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="10.1"
        data-chapter-title="ini配置"
        data-filepath="chapter10/10.1_ini配置.md"
        data-basepath=".."
        data-revision="Wed Oct 31 2018 20:17:52 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
                
                <li>
                    <a href="http://www.0voice.com" target="blank" class="custom-link">ntyTcp</a>
                </li>
            
            

            
            <li class="divider"></li>
            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter1/index.html">
            
                
                    <a href="../chapter1/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        课程介绍和项目介绍
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="chapter1/1.1_课程介绍.html">
            
                
                    <a href="../chapter1/1.1_课程介绍.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="chapter1/1.2_项目介绍.html">
            
                
                    <a href="../chapter1/1.2_项目介绍.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        项目介绍
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="chapter2/index.html">
            
                
                    <a href="../chapter2/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        搭建开发环境
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="chapter2/2.1_安装和配置linux系统.html">
            
                
                    <a href="../chapter2/2.1_安装和配置linux系统.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        安装和配置linux系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="chapter2/2.2_linux命令.html">
            
                
                    <a href="../chapter2/2.2_linux命令.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        linux命令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="chapter2/2.3_安装开发工具.html">
            
                
                    <a href="../chapter2/2.3_安装开发工具.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        安装开发工具
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="chapter2/2.4_搭建开发环境.html">
            
                
                    <a href="../chapter2/2.4_搭建开发环境.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        搭建开发环境
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="chapter3/index.html">
            
                
                    <a href="../chapter3/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        项目文档
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="chapter3/3.1_如何管理需求.html">
            
                
                    <a href="../chapter3/3.1_如何管理需求.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        如何管理需求
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="chapter3/3.1_如何架构设计.html">
            
                
                    <a href="../chapter3/3.1_如何架构设计.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        如何架构设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="chapter3/3.3_共享单车架构设计.html">
            
                
                    <a href="../chapter3/3.3_共享单车架构设计.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        共享单车的架构
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="chapter4/index.html">
            
                
                    <a href="../chapter4/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        敏捷开发
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="chapter4/4.1_敏捷概述.html">
            
                
                    <a href="../chapter4/4.1_敏捷概述.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        敏捷概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="chapter4/4.2_SCRUM介绍.html">
            
                
                    <a href="../chapter4/4.2_SCRUM介绍.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        SCRUM介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="chapter4/4.3_我们应该认识到.html">
            
                
                    <a href="../chapter4/4.3_我们应该认识到.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        我们应该认识到
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="chapter5/index.html">
            
                
                    <a href="../chapter5/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        持续集成
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="chapter5/5.1_lua语言介绍.html">
            
                
                    <a href="../chapter5/5.1_lua语言介绍.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        lua语言介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="chapter5/5.2_gtest单元测试.html">
            
                
                    <a href="../chapter5/5.2_gtest单元测试.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        gtest单元测试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="chapter5/5.3_搭建持续集成环境.html">
            
                
                    <a href="../chapter5/5.3_搭建持续集成环境.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        搭建持续集成环境
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="chapter6/index.html">
            
                
                    <a href="../chapter6/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        产品版本管理之git
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7" data-path="chapter7/index.html">
            
                
                    <a href="../chapter7/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        shell脚本
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="chapter7/7.1_什么是shell.html">
            
                
                    <a href="../chapter7/7.1_什么是shell.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        什么是shell
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="chapter7/7.2_Shell编程.html">
            
                
                    <a href="../chapter7/7.2_Shell编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        Shell编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="chapter7/7.3_启动脚本实例.html">
            
                
                    <a href="../chapter7/7.3_启动脚本实例.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        启动脚本实例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="chapter8/index.html">
            
                
                    <a href="../chapter8/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        项目编译
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="chapter8/8.1_编译原理.html">
            
                
                    <a href="../chapter8/8.1_编译原理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        编译原理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="chapter8/8.2_makefile.html">
            
                
                    <a href="../chapter8/8.2_makefile.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        makefile
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="chapter8/8.3_cmake.html">
            
                
                    <a href="../chapter8/8.3_cmake.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        cmake
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="chapter8/8.4_GNU_make.html">
            
                
                    <a href="../chapter8/8.4_GNU_make.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        GNU make
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="chapter9/index.html">
            
                
                    <a href="../chapter9/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        调试技巧
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="chapter9/9.1_gdb调试.html">
            
                
                    <a href="../chapter9/9.1_gdb调试.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        gdb调试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="chapter9/9.2_coredump.html">
            
                
                    <a href="../chapter9/9.2_coredump.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        coredump
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="chapter9/9.3_内存泄漏检查.html">
            
                
                    <a href="../chapter9/9.3_内存泄漏检查.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.3.</b>
                        
                        内存泄漏检查
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="chapter10/index.html">
            
                
                    <a href="../chapter10/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        项目配置文件
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="10.1" data-path="chapter10/10.1_ini配置.html">
            
                
                    <a href="../chapter10/10.1_ini配置.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        ini配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="chapter10/10.2_xml配置.html">
            
                
                    <a href="../chapter10/10.2_xml配置.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        xml配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.3" data-path="chapter10/10.3_lua配置.html">
            
                
                    <a href="../chapter10/10.3_lua配置.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.3.</b>
                        
                        lua配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="chapter11/index.html">
            
                
                    <a href="../chapter11/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        项目日志
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.1" data-path="chapter11/11.1_重定向.html">
            
                
                    <a href="../chapter11/11.1_重定向.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.1.</b>
                        
                        重定向
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="chapter11/11.2_log4cpp.html">
            
                
                    <a href="../chapter11/11.2_log4cpp.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.2.</b>
                        
                        log4cpp
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3" data-path="chapter11/11.3_大型项目的日志架构.html">
            
                
                    <a href="../chapter11/11.3_大型项目的日志架构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.3.</b>
                        
                        分布式系统的集中式日志解决方案
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12" data-path="chapter12/index.html">
            
            <span><b>12.</b> 进程</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="chapter12/12.1_进程的概念.html">
            
                
                    <a href="../chapter12/12.1_进程的概念.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        进程的概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="chapter12/12.2_如何产生一个进程.html">
            
                
                    <a href="../chapter12/12.2_如何产生一个进程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        如何产生一个进程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="chapter12/12.3_僵尸孤儿守护进程.html">
            
                
                    <a href="../chapter12/12.3_僵尸孤儿守护进程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.3.</b>
                        
                        僵尸、孤儿和守护进程
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="13" data-path="chapter13/index.html">
            
            <span><b>13.</b> 进程间通信</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="13.1" data-path="chapter13/13.1_管道与命名管道.html">
            
            <span><b>13.1.</b> 管道与命名管道</span>
            
            
        </li>
    
        <li class="chapter " data-level="13.2" data-path="chapter13/13.2_共享内存.html">
            
            <span><b>13.2.</b> 共享内存</span>
            
            
        </li>
    
        <li class="chapter " data-level="13.3" data-path="chapter13/13.3_信号量.html">
            
            <span><b>13.3.</b> 信号量</span>
            
            
        </li>
    
        <li class="chapter " data-level="13.4" data-path="chapter13/13.4_信号.html">
            
            <span><b>13.4.</b> 信号</span>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="14" data-path="chapter14/index.html">
            
                
                    <a href="../chapter14/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.</b>
                        
                        网络协议
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="14.1" data-path="chapter14/14.1_俗话网络通信.html">
            
                
                    <a href="../chapter14/14.1_俗话网络通信.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.1.</b>
                        
                        俗话网络通信
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.2" data-path="chapter14/14.2_网络7层协议与4层协议.html">
            
                
                    <a href="../chapter14/14.2_网络7层协议与4层协议.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.2.</b>
                        
                        网络7层协议与4层协议
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >课程介绍</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="101-ini&#x914D;&#x7F6E;">10.1 ini&#x914D;&#x7F6E;</h1>
<p>&#x2003;&#x2003;&#x6211;&#x4EEC;&#x5148;&#x6765;&#x770B;&#x4E0B;ini&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x662F;&#x5565;&#xFF0C;&#x4F8B;&#x5982;&#x6211;&#x4EEC;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5982;&#x4E0B;&#xFF0C;database&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x7684;&#x4FD7;&#x79F0;&#x7684;&#x533A;&#x6BB5;&#xFF0C;ip&#xFF0C;port&#x5C31;&#x662F;&#x5B57;&#x6BB5;&#xFF0C;127.0.0.1&#x548C;3306&#x5C31;&#x662F;&#x5B57;&#x6BB5;&#x7684;&#x503C;&#x3002;</p>
<pre><code>[database]
ip       = 127.0.0.1 ;
port     = 3306 ;
user     = root ;
pwd      = 123456 ;
db       = dongnaobike;

[server]
port     = 9090
</code></pre><p>&#x2003;&#x2003;OK&#xFF0C;&#x90A3;&#x6211;&#x4EEC;&#x600E;&#x4E48;&#x5B9E;&#x73B0;&#x4ECE;ini&#x6587;&#x4EF6;&#x91CC;&#x52A0;&#x8F7D;&#x4E0A;&#x8FD9;&#x4E9B;&#x5185;&#x5BB9;&#x5462;&#xFF1F;&#x9996;&#x5148;&#x5206;&#x6790;&#x5C31;&#x662F;&#x8BFB;&#x53D6;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#xFF0C;&#x7136;&#x540E;&#x4F9D;&#x7167;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#xFF0C;&#x628A;&#x8FD9;&#x4E9B;&#x5B57;&#x6BB5;&#x548C;&#x503C;&#x7EC4;&#x6210;key-value&#x7684;&#x5F62;&#x5F0F;&#x4FDD;&#x5B58;&#x5728;&#x67D0;&#x4E2A;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x4E2D;&#xFF0C;&#x8FD9;&#x6837;&#x6211;&#x4EEC;&#x901A;&#x8FC7;key&#xFF08;&#x533A;&#x6BB5;+&#x5B57;&#x6BB5;&#xFF09;&#x5C31;&#x80FD;&#x627E;&#x5230;value&#xFF08;&#x503C;&#xFF09;&#xFF0C;&#x90A3;&#x5982;&#x4F55;&#x8BBE;&#x8BA1;&#x8FD9;&#x4E2A;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x5462;&#xFF1F;<br>&#x2003;&#x2003;&#x6700;&#x5BB9;&#x6613;&#x60F3;&#x5230;&#x7684;&#x5C31;&#x662F;&#x5B57;&#x5178;&#x4E86;&#xFF08;dictionary&#xFF09;&#xFF0C;&#x8FD9;&#x4E2A;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x7684;&#x8BFE;&#x5802;&#x4E0A;&#x5E94;&#x8BE5;&#x5B66;&#x8FC7;&#x5427;&#xFF0C;&#x5B57;&#x5178;&#x662F;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x5E38;&#x7528;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x4E86;&#xFF0C;&#x5982;&#x679C;&#x5927;&#x5BB6;&#x6709;&#x5174;&#x8DA3;&#x8FD8;&#x53EF;&#x4EE5;&#x53BB;&#x6DF1;&#x5EA6;&#x63A2;&#x7D22;&#x4E0B;redis&#x7684;&#x5B58;&#x50A8;&#x7ED3;&#x6784;&#xFF0C;&#x4E5F;&#x7528;&#x5230;&#x4E86;&#x5B57;&#x5178;&#xFF0C;&#x53EA;&#x4E0D;&#x8FC7;&#x5B83;&#x7684;&#x90A3;&#x4E2A;&#x5B57;&#x5178;&#x8BBE;&#x8BA1;&#x66F4;&#x52A0;&#x590D;&#x6742;&#x800C;&#x5DF2;&#x3002;</p>
<pre><code>typedef struct _dictionary_ {
    int            n ;  /** &#x5B57;&#x5178;&#x4E2D;&#x5DF2;&#x7ECF;&#x5B58;&#x50A8;&#x7684;&#x4E2A;&#x6570; */
    ssize_t        size ;  /** &#x5B57;&#x5178;&#x4E2D;&#x8282;&#x70B9;&#x7684;&#x4E2A;&#x6570; */
    char        **  val ;  /** value&#x5217;&#x8868; */
    char        **  key ;  /** key&#x5217;&#x8868; */
    unsigned     *  hash ;  /** hash&#x503C;&#x5217;&#x8868; */
} dictionary ;
</code></pre><p>&#x2003;&#x2003;&#x90A3;&#x4ED6;&#x662F;&#x5982;&#x4F55;&#x5B58;&#x50A8;&#x6570;&#x636E;&#x7684;&#x5462;&#xFF1F;&#x6211;&#x4EEC;&#x9996;&#x5148;&#x6765;&#x770B;&#x5B83;&#x8FD8;&#x5E94;&#x5F53;&#x63D0;&#x4F9B;&#x7684;&#x63A5;&#x53E3;&#xFF1A;  </p>
<pre><code>dictionary * dictionary_new(size_t size);
void dictionary_del(dictionary * vd);
unsigned dictionary_hash(const char * key);
const char * dictionary_get(const dictionary * d, const char * key, const char * def);
int dictionary_set(dictionary * vd, const char * key, const char * val);
void dictionary_unset(dictionary * d, const char * key);
void dictionary_dump(const dictionary * d, FILE * out);
</code></pre><p>&#x2003;&#x2003;&#x81EA;&#x7136;&#x4E0D;&#x7528;&#x8BF4;&#xFF0C;&#x6211;&#x4EEC;&#x9996;&#x5148;&#x5F97;&#x901A;&#x8FC7;dictionary_new&#x63A5;&#x53E3;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5B57;&#x5178;&#xFF0C;&#x521B;&#x5EFA;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF0C;&#x5176;&#x5B9E;val&#x548C;key&#x90FD;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;hash&#x662F;&#x4E00;&#x4E2A;&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x5F62;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5B57;&#x5178;&#x5C31;&#x662F;&#x9996;&#x5148;&#x5206;&#x914D;&#x5185;&#x5B58;&#xFF1A;</p>
<pre><code>dictionary * dictionary_new(size_t size)
{
    dictionary  *   d ;

    /* If no size was specified, allocate space for DICTMINSZ */
    if (size&lt;DICTMINSZ) size=DICTMINSZ ;

    d = (dictionary*) calloc(1, sizeof *d) ;

    if (d) {
        d-&gt;size = size ;
        d-&gt;val  = (char**) calloc(size, sizeof *d-&gt;val);
        d-&gt;key  = (char**) calloc(size, sizeof *d-&gt;key);
        d-&gt;hash = (unsigned*) calloc(size, sizeof *d-&gt;hash);
    }
    return d ;
}
</code></pre><p>&#x2003;&#x2003;&#x521B;&#x5EFA;&#x4E86;&#x5B57;&#x5178;&#xFF0C;&#x90A3;&#x5982;&#x4F55;&#x5F80;&#x5B57;&#x5178;&#x91CC;&#x63D2;&#x5165;key-value&#x5BF9;&#x5462;&#xFF1F;&#x4E0A;&#x9762;&#x7684;&#x8FD9;&#x4E2A;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x8FD9;&#x6837;&#x7684;&#x4E00;&#x4E2A;&#x4E1C;&#x897F;&#xFF0C;&#x7528;&#x56FE;&#x8868;&#x793A;&#x5982;&#x4E0B;&#xFF1A;
<img src="10_1.png" alt="&#x5B57;&#x5178;&#x7ED3;&#x6784;">
&#x4ECE;&#x4E0A;&#x56FE;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x96BE;&#x7406;&#x89E3;&#xFF0C;&#x5C31;&#x662F;&#x5728;&#x63D2;&#x5165;key-value&#x65F6;&#xFF0C;&#x9996;&#x5148;&#x8BA1;&#x7B97;&#x51FA;&#x4E00;&#x4E2A;key&#x7684;hash&#x503C;&#xFF08;hash&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x628A;hash-key-value&#x4E09;&#x5143;&#x7EC4;&#x5B58;&#x653E;&#x5728;&#x4E0A;&#x56FE;&#x7684;&#x7ED3;&#x6784;&#x7684;&#x4F4D;&#x7F6E;d-&gt;n&#x4F4D;&#x7F6E;&#xFF0C;&#x6700;&#x540E;d-&gt;n&#x79FB;&#x52A8;&#x4E00;&#x4E2A;&#x4F4D;&#x7F6E;&#xFF0C;&#x53EA;&#x4E0D;&#x8FC7;&#x6211;&#x4EEC;&#x5728;&#x5B58;&#x653E;&#x8FD9;&#x4E2A;hash-key-value&#x8FD9;&#x4E2A;&#x4E09;&#x5143;&#x7EC4;&#x4E4B;&#x524D;&#x8981;&#x505A;&#x5404;&#x79CD;&#x5224;&#x65AD;&#xFF0C;&#x5982;&#xFF1A;</p>
<ul>
<li>hash&#x503C;&#x662F;&#x5426;&#x5728;&#x5B57;&#x5178;&#x4E2D;&#x5B58;&#x5728;&#xFF0C;&#x5982;&#x679C;&#x5B58;&#x5728;&#x5219;&#x66F4;&#x65B0;key&#x548C;value&#xFF1B;</li>
<li>&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x8D85;&#x51FA;&#x4E86;&#x5B57;&#x5178;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x7684;&#x5219;&#x9700;&#x8981;&#x6269;&#x5145;&#x5B57;&#x5178;&#x7684;&#x8282;&#x70B9;&#x4E2A;&#x6570;&#xFF08;&#x5F53;&#x524D;&#x5927;&#x5C0F;&#x7684;&#x4E24;&#x500D;&#xFF09;&#xFF1B;</li>
<li>&#x627E;&#x5230;d-&gt;n&#x4F4D;&#x7F6E;&#xFF1B;</li>
</ul>
<pre><code>int dictionary_set(dictionary * d, const char * key, const char * val)
{
    ssize_t         i ;
    unsigned       hash ;

    if (d==NULL || key==NULL) return -1 ;

    /* Compute hash for this key */
    hash = dictionary_hash(key) ;
    /* Find if value is already in dictionary */
    if (d-&gt;n&gt;0) {
        for (i=0 ; i&lt;d-&gt;size ; i++) {
            if (d-&gt;key[i]==NULL)
                continue ;
            if (hash==d-&gt;hash[i]) { /* Same hash value */
                if (!strcmp(key, d-&gt;key[i])) {   /* Same key */
                    /* Found a value: modify and return */
                    if (d-&gt;val[i]!=NULL)
                        free(d-&gt;val[i]);
                    d-&gt;val[i] = (val ? xstrdup(val) : NULL);
                    /* Value has been modified: return */
                    return 0 ;
                }
            }
        }
    }
    /* Add a new value */
    /* See if dictionary needs to grow */
    if (d-&gt;n==d-&gt;size) {
        /* Reached maximum size: reallocate dictionary */
        if (dictionary_grow(d) != 0)
            return -1;
    }

    /* Insert key in the first empty slot. Start at d-&gt;n and wrap at
       d-&gt;size. Because d-&gt;n &lt; d-&gt;size this will necessarily
       terminate. */
    for (i=d-&gt;n ; d-&gt;key[i] ; ) {
        if(++i == d-&gt;size) i = 0;
    }
    /* Copy key */
    d-&gt;key[i]  = xstrdup(key);
    d-&gt;val[i]  = (val ? xstrdup(val) : NULL) ;
    d-&gt;hash[i] = hash;
    d-&gt;n ++ ;
    return 0 ;
}
</code></pre><p>&#x2003;&#x2003;&#x90A3;&#x5982;&#x4F55;&#x4ECE;&#x5B57;&#x5178;&#x4E2D;&#x53D6;&#x6570;&#x636E;&#x5462;&#xFF1F;&#x6211;&#x4EEC;&#x5148;&#x6765;&#x770B;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#xFF1A;  </p>
<pre><code>const char * dictionary_get(const dictionary * d, const char * key, const char * def);
</code></pre><p>&#x4E5F;&#x5C31;&#x662F;&#x8981;&#x901A;&#x8FC7;key&#x8FD4;&#x56DE;&#x5BF9;&#x5E94;&#x7684;value&#xFF0C;&#x4ECE;&#x4E0A;&#x56FE;&#x6211;&#x4EEC;&#x66F4;&#x52A0;&#x8981;&#x77E5;&#x9053;&#xFF0C;&#x6211;&#x4EEC;&#x53BB;&#x627E;&#x8FD9;&#x4E2A;value&#x5C31;&#x662F;&#x8981;&#x627E;&#x5230;&#x5BF9;&#x5E94;&#x7684;key&#x7684;hash&#x503C;&#x6240;&#x5728;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x9996;&#x5148;&#x8BA1;&#x7B97;key&#x7684;hash&#x503C;&#xFF0C;&#x5F97;&#x5230;&#x8FD9;&#x4E2A;hash&#x503C;&#x540E;&#x4ECE;d-&gt;hash&#x6570;&#x7EC4;&#x91CC;&#x904D;&#x5386;&#x51FA;hash&#x503C;&#xFF0C;&#x7136;&#x540E;&#x5BF9;&#x5E94;&#x6570;&#x7EC4;&#x7684;&#x4E0B;&#x6807; i &#x5C31;&#x662F;key&#x548C;value&#x6240;&#x5728;d-&gt;key &#x548C; d-&gt;value&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x8FD9;&#x6837;&#x53D6;&#x8D70;&#x5C31;&#x884C;&#x3002;&#x597D;&#x7684;&#xFF0C;&#x6765;&#x770B;&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre><code>const char * dictionary_get(const dictionary * d, const char * key, const char * def)
{
    unsigned    hash ;
    ssize_t      i ;

    hash = dictionary_hash(key);
    for (i=0 ; i&lt;d-&gt;size ; i++) {
        if (d-&gt;key[i]==NULL)
            continue ;
        /* Compare hash */
        if (hash==d-&gt;hash[i]) {
            /* Compare string, to avoid hash collisions */
            if (!strcmp(key, d-&gt;key[i])) {
                return d-&gt;val[i] ;
            }
        }
    }
    return def ;
}
</code></pre><p>OK&#xFF0C;&#x4E86;&#x89E3;&#x4E86;&#x6700;&#x57FA;&#x672C;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#xFF0C;&#x90A3;&#x5C31;&#x662F;&#x89E3;&#x6790;ini&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x4E86;&#xFF0C;&#x8FD9;&#x4E2A;&#x4E0D;&#x518D;&#x7EC6;&#x8BB2;&#xFF0C;&#x8BE6;&#x89C1;&#x5F00;&#x6E90;&#x5E93;&#x7684;&#x5B9E;&#x73B0;<a href="https://github.com/ndevilla/iniparser" target="_blank">https://github.com/ndevilla/iniparser</a>&#x3002;</p>
<p>&#x6700;&#x7EC8;&#x6765;&#x770B;&#x4E0B;&#x6211;&#x4EEC;&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x5F00;&#x6E90;&#x5E93;&#x7684;&#xFF1A;</p>
<pre><code>typedef struct st_env_config
{
   //&#x6570;&#x636E;&#x5E93;&#x7684;&#x914D;&#x7F6E;
   std::string db_ip;
   unsigned short db_port;
   std::string db_user;
   std::string db_pwd;
   std::string db_name;

   //&#x670D;&#x52A1;&#x7684;&#x914D;&#x7F6E;
   unsigned short svr_port;

   st_env_config()
   {
   };

   st_env_config(const std::string&amp; db_ip, unsigned int db_port, const std::string&amp; db_user, \
                 const std::string&amp; db_pwd, const std::string&amp; db_name, unsigned short svr_port)
   {
       this-&gt;db_ip    = db_ip;
       this-&gt;db_port  = db_port;
       this-&gt;db_user  = db_user;
       this-&gt;db_pwd   = db_pwd;
       this-&gt;db_name  = db_name;
       this-&gt;svr_port = svr_port;
   };

   st_env_config&amp; operator =(const st_env_config&amp; config)
   {
       if (this != &amp;config)
       {
           this-&gt;db_ip    = config.db_ip;
           this-&gt;db_port  = config.db_port;
           this-&gt;db_user  = config.db_user;
           this-&gt;db_pwd      = config.db_pwd;
           this-&gt;db_name  = config.db_name;
           this-&gt;svr_port = config.svr_port;

        }
        return *this;
    }
}_st_env_config;

bool Iniconfig::loadfile(const std::string&amp; path)
{
    dictionary*   ini = NULL;

    ini = iniparser_load(path.c_str());
    if (ini==NULL)
    {
        LOG_ERROR(&quot;cannot parse file: %s\n&quot;, path.c_str());
        return false;
    }

    char* ip    = iniparser_getstring(ini, &quot;database:ip&quot;, &quot;127.0.0.1&quot;);
    int   port  = iniparser_getint(ini, &quot;database:port&quot;, 3306);
    char* user  = iniparser_getstring(ini, &quot;database:user&quot;, &quot;root&quot;);
    char* pwd   = iniparser_getstring(ini, &quot;database:pwd&quot;, &quot;123456&quot;);
    char* db    = iniparser_getstring(ini, &quot;database:db&quot;, &quot;dongnaobike&quot;);
    int   sport = iniparser_getint(ini, &quot;server:port&quot;, 9090);

    _config = st_env_config(std::string(ip), port, std::string(user), \
        std::string(pwd), std::string(db), sport);

    iniparser_freedict(ini);

    _isloaded = true;

    return true;
}
</code></pre>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../chapter10/index.html" class="navigation navigation-prev " aria-label="Previous page: 项目配置文件"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../chapter10/10.2_xml配置.html" class="navigation navigation-next " aria-label="Next page: xml配置"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"theme-default":{"showLevel":false},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
